﻿Imports System.Data.OleDb
Partial Public Class addpictures
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim title As String = tb_title.Text
        If FileUpload1.HasFile Then
            Dim filename = FileUpload1.FileName
            Dim webrootfolder = Request.MapPath(".")
            Dim imagefolder = webrootfolder & "/images/"
            FileUpload1.SaveAs(imagefolder & filename)
            Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("picturesConnectionString3").ConnectionString)
            Dim sql As String = "INSERT INTO images (Title,ImageUrl) VALUES (@Title,@ImageURL)"
            Dim cmd As New OleDbCommand(sql, oleDbConn)
            cmd.Parameters.AddWithValue("@Title", title)
            cmd.Parameters.AddWithValue("@ImageURL", "images/" & filename)
            oleDbConn.Open()
            cmd.ExecuteNonQuery()
            oleDbConn.Close()

            If FileUpload1.HasFile = False Then FileUploadDetails.Text = "Please First Select File to Upload.... "

        Else
            FileUploadDetails.Text = String.Format("File Upload {0} <br/>" & "File size :(in Bytes):{1:NO} <br/>" & "Content-type: {2}", FileUpload1.FileBytes.Length, FileUpload1.PostedFile.ContentType)
        End If


    End Sub
End Class